{% extends 'base.html' %}
{% load static %}

{% block title %}个人资料 - 电影院票务管理系统{% endblock %}

{% block content %}
<div class="row">
    <!-- 用户信息 -->
    <div class="col-md-4 mb-4">
        <div class="card">
            <div class="card-header">
                <h5 class="mb-0"><i class="fas fa-user me-2"></i>个人信息</h5>
            </div>
            <div class="card-body text-center">
                {% if profile.avatar %}
                    <img src="{{ profile.avatar.url }}" class="rounded-circle mb-3" width="100" height="100" alt="头像">
                {% else %}
                    <div class="rounded-circle bg-secondary d-inline-flex align-items-center justify-content-center mb-3" style="width: 100px; height: 100px;">
                        <i class="fas fa-user fa-3x text-white"></i>
                    </div>
                {% endif %}
                <h5>{{ user.username }}</h5>
                <p class="text-muted">{{ user.email }}</p>
                <div class="d-flex justify-content-between">
                    <span class="badge bg-primary">积分: {{ profile.points }}</span>
                    <span class="badge bg-success">会员</span>
                </div>
            </div>
        </div>
    </div>
    
    <!-- 资料编辑 -->
    <div class="col-md-8 mb-4">
        <div class="card">
            <div class="card-header">
                <h5 class="mb-0"><i class="fas fa-edit me-2"></i>编辑资料</h5>
            </div>
            <div class="card-body">
                <form method="post" enctype="multipart/form-data">
                    {% csrf_token %}
                    <div class="row">
                        <div class="col-md-6 mb-3">
                            <label class="form-label">用户名</label>
                            <input type="text" class="form-control" value="{{ user.username }}" readonly>
                        </div>
                        <div class="col-md-6 mb-3">
                            <label class="form-label">邮箱</label>
                            <input type="email" class="form-control" value="{{ user.email }}" readonly>
                        </div>
                    </div>
                    <div class="mb-3">
                        <label class="form-label">手机号</label>
                        {{ form.phone }}
                        {% if form.phone.errors %}
                            <div class="text-danger small">{{ form.phone.errors.0 }}</div>
                        {% endif %}
                    </div>
                    <div class="mb-3">
                        <label class="form-label">头像</label>
                        {{ form.avatar }}
                        {% if form.avatar.errors %}
                            <div class="text-danger small">{{ form.avatar.errors.0 }}</div>
                        {% endif %}
                    </div>
                    <button type="submit" class="btn btn-primary">
                        <i class="fas fa-save me-1"></i>保存修改
                    </button>
                </form>
            </div>
        </div>
    </div>
</div>

<!-- 订单历史 -->
<div class="row">
    <div class="col-12">
        <div class="card">
            <div class="card-header">
                <h5 class="mb-0"><i class="fas fa-history me-2"></i>订单历史</h5>
            </div>
            <div class="card-body">
                {% if orders %}
                    <div class="table-responsive">
                        <table class="table table-hover">
                            <thead>
                                <tr>
                                    <th>订单号</th>
                                    <th>电影</th>
                                    <th>场次</th>
                                    <th>座位</th>
                                    <th>金额</th>
                                    <th>状态</th>
                                    <th>时间</th>
                                    <th>操作</th>
                                </tr>
                            </thead>
                            <tbody>
                                {% for order in orders %}
                                    <tr>
                                        <td>{{ order.order_id }}</td>
                                        <td>{{ order.screening.movie.title }}</td>
                                        <td>{{ order.screening.start_time|date:"m-d H:i" }}</td>
                                        <td>
                                            {% for seat in order.seats.all %}
                                                <span class="badge bg-info me-1">{{ seat.seat_number }}</span>
                                            {% endfor %}
                                        </td>
                                        <td>¥{{ order.total_amount }}</td>
                                        <td>
                                            {% if order.status == 'pending' %}
                                                <span class="badge bg-warning">待支付</span>
                                            {% elif order.status == 'paid' %}
                                                <span class="badge bg-success">已支付</span>
                                            {% elif order.status == 'completed' %}
                                                <span class="badge bg-info">已完成</span>
                                            {% else %}
                                                <span class="badge bg-secondary">已取消</span>
                                            {% endif %}
                                        </td>
                                        <td>{{ order.created_at|date:"m-d H:i" }}</td>
                                        <td>
                                            <a href="{% url 'order_detail' order.id %}" class="btn btn-sm btn-outline-primary">
                                                <i class="fas fa-eye me-1"></i>查看
                                            </a>
                                        </td>
                                    </tr>
                                {% endfor %}
                            </tbody>
                        </table>
                    </div>
                {% else %}
                    <div class="text-center py-4">
                        <i class="fas fa-ticket-alt fa-3x text-muted mb-3"></i>
                        <p class="text-muted">暂无订单记录</p>
                        <a href="{% url 'movie_list' %}" class="btn btn-primary">
                            <i class="fas fa-film me-1"></i>去购票
                        </a>
                    </div>
                {% endif %}
            </div>
        </div>
    </div>
</div>
{% endblock %} 